<?php
namespace App\Http\Controllers\ConsoleWeb;

use App\Http\Controllers\WebController;
use App\Http\Controllers\Business\Admin\User\UserMamagement;
use App\Http\Controllers\Business\Admin\Shop\ShopManagement;
use App\Http\Controllers\Business\Admin\Common\Common;
use App\Models\Feedback;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Support\Facades\Auth;
use App\Models\Oss;
use Maatwebsite\Excel\Facades\Excel;

class UserController extends WebController
{
    //用户列表
    public function userList() {
        $perpage = 50; //默认显示50条
        $cityId = $this->request->get('cityid');
        if($this->request->has('search')) {
            $search = $this->request->get('search');
            $skip = 0;
            $take = $perpage;
            $page=1;
        } else {
            if ($this->request->has('page')) {
                $page = $this->request->get('page');
            } else {
                $page = 1;
            }
            $skip = ($page-1)*$perpage;
            $take = $perpage;
            $search = '';
        }
        if($this->request->has('starttime')) {
            $startTime = $this->request->get('starttime');
            $lastTime = $this->request->get('lasttime');
            $startTime = date('Y-m-d',strtotime($startTime)) . " 00:00:00";
            $lastTime = date('Y-m-d',strtotime($lastTime)) . " 23:59:59";
        } else {
            if($this->request->has('type')) {
                $type = $this->request->get('type');
            } else {
                $type = 'all';
            }
            if($type == 'today') {
                $startTime = date('Y-m-d') . ' 00:00:00';
                $lastTime = date('Y-m-d') . ' 23:59:59';;
            } elseif($type == 'yesterday') {
                $startTime = date('Y-m-d', strtotime("-1day")) . ' 00:00:00';
                $lastTime = date('Y-m-d', strtotime("-1day")) . ' 23:59:59';
            } elseif($type == 'week') {
                $startTime = date("Y-m-d",strtotime("-1 week Monday")) . " 00:00:00";
                $lastTime = date('Y-m-d') . " 23:59:59";
            } elseif($type == 'thismonth') {
                $startTime = date('Y-m') . "-01 00:00:00";
                $lastTime = date('Y-m-d') . " 23:59:59";
            } elseif($type == 'lastmonth') {
                $firstDay = date("Y-m-01");
                $startTime = date('Y-m-01', strtotime($firstDay)-86400) . " 00:00:00";
                $lastTime = date("Y-m-d", strtotime($firstDay)-86400) . " 23:59:59";
            } elseif($type == 'all') {
                $startTime = "2016-07-01 00:00:00";
                $lastTime = date("Y-m-d") . " 23:59:59";
            } else {
                return view('errors.404');
            }
        }

        $status = '%';
        $count = UserMamagement::getUserCountByFromDateAndToDate($cityId, $startTime, $lastTime);
        $lastPage = ceil($count/$perpage);
        $result = UserMamagement::userList($startTime, $lastTime, $status, $search, $skip, $take);
        if($result['status'] == 'failed') {
            return view('errors.404');
        }
        $lists = $result['data'];
        $data = [
            'lists' => $lists,
            'cityid' => $cityId,
            'page' => $page,
            'lastpage' => $lastPage,
            'perpage' => $perpage,
            'starttime' => $startTime,
            'lasttime' => $lastTime,
            'search' => $search,
        ];
        return view('console.user.user_list', $data);
    }
    //用户详细
    public function getUser() {
        $cityId = $this->request->get('cityid');
        $userId = $this->request->get('userid');
        $result = UserMamagement::getUser($userId);
        if($result['status'] == 'failed') {
            return view('errors.404');
        }
        $data = $result['data'];
        $data['cityid'] = $cityId;
        return view('console.user.user_details', $data);
    }
    //通过类型（充值，消费，评论， 红包）获取用户信息
    public function getUserInfoByType() {
        $cityId = $this->request->get('cityid');
        $userId = $this->request->get('userid');
        $type = $this->request->get('type');
        if($this->request->has('page')) {
            $page = $this->request->get('page');
        } else {
            $page = 1;
        }
        if($this->request->has('length')) {
            $length = $this->request->get('length');
        } else {
            $length = 10;
        }
        $skip = ($page-1)* $length;
        $result = UserMamagement::getUserInfoByType($userId, $type, $skip, $length);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        $data = $result['data'];
        return $this->responseSuccessData($data);
    }
    //编辑用户
    public function editUser() {
        $userId = $this->request->get('userid');
        $isDouble = $this->request->get('isdouble');
        $type = $this->request->get('type');
        if($type == 'isdouble') {
            $result = UserMamagement::updateUserIsDouble($userId,$isDouble);
        } else {
            return $this->responseError('类型不对');
        }
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessMessage($result['message']);
        }
    }
    //更新用户状态
    public function editUserStatus() {
        $userId = $this->request->get('userid');
        $type = $this->request->get('type');
        $result = UserMamagement::updateUserStatus($userId, $type);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessMessage($result['message']);
        }
    }
    //删除用户
    public function deleteUser() {
        $userId = $this->request->get('userid');
        $result = UserMamagement::updateUser($userId);
        if($result['status'] == 'failed') {
            return view('errors.404');
        }
        $data = $result['data'];
        return view('console.user.user_details', $data);
    }
    //地区用户列表
    public function regionUserList() {
        $perpage = 50; //默认显示50条
        $cityId = $this->request->get('cityid');
        if($this->request->has('search')) {
            $search = $this->request->get('search');
            $skip = 0;
            $take = $perpage;
            $page=1;
        } else {
            if ($this->request->has('page')) {
                $page = $this->request->get('page');
            } else {
                $page = 1;
            }
            $skip = ($page-1)*$perpage;
            $take = $perpage;
            $search = '';
        }
        if($this->request->has('starttime')) {
            $startTime = $this->request->get('starttime');
            $lastTime = $this->request->get('lasttime');
            $startTime = date('Y-m-d',strtotime($startTime)) . " 00:00:00";
            $lastTime = date('Y-m-d',strtotime($lastTime)) . " 23:59:59";
        } else {
            if($this->request->has('type')) {
                $type = $this->request->get('type');
            } else {
                $type = 'all';
            }
            if($type == 'today') {
                $startTime = date('Y-m-d') . ' 00:00:00';
                $lastTime = date('Y-m-d') . ' 23:59:59';;
            } elseif($type == 'yesterday') {
                $startTime = date('Y-m-d', strtotime("-1day")) . ' 00:00:00';
                $lastTime = date('Y-m-d', strtotime("-1day")) . ' 23:59:59';
            } elseif($type == 'week') {
                $startTime = date("Y-m-d",strtotime("-1 week Monday")) . " 00:00:00";
                $lastTime = date('Y-m-d') . " 23:59:59";
            } elseif($type == 'thismonth') {
                $startTime = date('Y-m') . "-01 00:00:00";
                $lastTime = date('Y-m-d') . " 23:59:59";
            } elseif($type == 'lastmonth') {
                $firstDay = date("Y-m-01");
                $startTime = date('Y-m-01', strtotime($firstDay)-86400) . " 00:00:00";
                $lastTime = date("Y-m-d", strtotime($firstDay)-86400) . " 23:59:59";
            } elseif($type == 'all') {
                $startTime = "2016-07-01 00:00:00";
                $lastTime = date("Y-m-d") . " 23:59:59";
            } else {
                return view('errors.404');
            }
        }
        $count = UserMamagement::getRegionUserCountByFromDateAndToDate($cityId, $startTime, $lastTime, $search);
        $lastPage = ceil($count/$perpage);
        $result = UserMamagement::regionUserList($cityId, $startTime, $lastTime, $search, $skip, $take);
        if($result['status'] == 'failed') {
            return view('errors.404');
        }
        $data = [
            'cityid' => $cityId,
            'lists' => $result['data'],
            'count' => $count,
            'page' => $page,
            'lastpage' => $lastPage,
            'perpage' => $perpage,
            'starttime' => $startTime,
            'lasttime' => $lastTime,
            'search' => $search,
        ];
        return view('console.user.regoin_user_list', $data);
    }
    //地区用户详情
    public function regionUserDetails() {
        $userId = $this->request->get('userid');
        $cityId = $this->request->get('cityid');
        $result = UserMamagement::getUser($userId);
        if($result['status'] == 'failed') {
            return view('errors.404');
        }
        $data = $result['data'];
        $data['cityid'] = $cityId;
        $data['mobile'] = str_replace(substr($data['mobile'], 3, 4), '****', $data['mobile']);
        return view('console.user.regoin_user_details', $data);
    }
    //[代]红包管理
    public function redEnvelope() {
        $cityId = $this->request->get('cityid');
        $result = UserMamagement::getAgentRedEnvelope($cityId);
        if($result['status'] == 'failed') {
            return view('errors.404');
        }
        $data = $result['data'];
        $data['cityid'] = $cityId;
        return view('console.user.red_envelope', $data);
    }
    //[代]设置红包管理
    public function updateRedEnvelopeAgentRatio() {
        $cityId = $this->request->get('cityid');
        if($this->request->has('red_agentratio')) {
            $agentRatio = $this->request->get('red_agentratio');
        } else {
            $agentRatio = 0;
        }
        $agentFee = 0.7;
        $agentRatio = round($agentRatio * $agentFee, 2);
        if($this->request->has('validdays')) {
            $validDays = $this->request->get('validdays');
        } else {
            $validDays = 0;
        }
        $result = UserMamagement::updateAgentRedEnvelopeAgentRatio($cityId,$agentRatio, $validDays);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessMessage($result['message']);
        }
    }
    //历史设置记录
    public function redEnvelopeHistoric() {
        $cityId = $this->request->get('cityid');
        $result = UserMamagement::redEnvelopeLogList($cityId);
        if($result['status'] == 'failed') {
            return view('errors.404');
        }
        $lists = $result['data'];
        $data = ['lists'=>$lists];
        return view('console.user.red_envelope_historic', $data);
    }
    //Banner列表
    public function bannerList() {
        $cityId = $this->request->get('cityid');
        $bannerResult = UserMamagement::bannerList($cityId);
        if($bannerResult['status'] == 'failed') {
            return view('errors.404');
        }
        $bannerLists = $bannerResult['data'];
        $adminUser = Auth::guard('adminweb')->user();
        $roleId = $adminUser->roleid;
        if(($roleId != 1) && ($roleId != 2) && ($roleId != 5) && ($roleId != 7)) {
            $isGlobal = 0;
        } else {
            $isGlobal = 1;
        }
        $data = [
            'bannerlists' => $bannerLists,
            'cityid' => $cityId,
            'isglobal' => $isGlobal,
        ];
        return view('console.user.banner_list', $data);
    }
    //获取Banner，新增banner
    public function getBanner() {
        $adminUserId = Auth::guard('adminweb')->id();
        $cityId = $this->request->get('cityid');
        $action = $this->request->get('action');
        $ossData = Oss::getStsAuth();
        $AccessKeyId = isset($ossData['AccessKeyId']) ? $ossData['AccessKeyId']:'';
        $AccessKeySecret = isset($ossData['AccessKeySecret']) ? $ossData['AccessKeySecret']:'';
        $SecurityToken = isset($ossData['SecurityToken']) ? $ossData['SecurityToken']:'';
        if($this->request->has('bannerid')) {
            //编辑
            $bannerId = $this->request->get('bannerid');
            $result = UserMamagement::getBanner($bannerId);
            if($result['status'] == 'failed') {
                return view('errors.404');
            }
            $data = $result['data'];
            $data['AccessKeyId'] = $AccessKeyId;
            $data['AccessKeySecret'] = $AccessKeySecret;
            $data['SecurityToken'] = $SecurityToken;
            $data['cityid'] = $cityId;
            $data['adminUserId'] = $adminUserId;
            $data['action'] = $action;
            if(isset($data['type']) && ($data['type'] == 'shop')) {
                $shopId = $data['content'];
                $shopNameResult = ShopManagement::getShopNameByShopId($shopId);
                if($shopNameResult['status'] == 'failed') {
                    $shopName = '';
                } else {
                    $shopName = $shopNameResult['data'];
                }
            } else {
                $shopId = "";
                $shopName = "";
            }
            $adminUser = Auth::guard('adminweb')->user();
            $data['roleid'] = $adminUser->roleid;
            $data['shopid'] = $shopId;
            $data['shopname'] = $shopName;
            return view('console.user.banner_modify', $data);
        } else {
            //新增
            $adminUser = Auth::guard('adminweb')->user();
            $data = [
                'bannerid' => '',
                'name' => '',
                'url' => '',
                'isglobal' => '0',
                'type' => '',
                'sort' => '',
                'islogin' => '',
                'created_at' => date('Y-m-d H:i:s'),
                'AccessKeyId' => $AccessKeyId,
                'AccessKeySecret' => $AccessKeySecret,
                'SecurityToken' => $SecurityToken,
                'roleid' => $adminUser->roleid,
                'cityid' => $cityId,
                'adminUserId' => $adminUserId,
                'action' => $action,
                'content' => '',
                'shopid' => '',
                'shopname' => '',
                'starttime' => date('Y-m-d')
            ];
            return view('console.user.banner_modify', $data);
        }
    }
    //编辑Banner, 新增
    public function editBanner() {
        $bannerId = $this->request->get('bannerid');
        $name = $this->request->get('name');
        $url = $this->request->get('banner');
        $isGlobal = $this->request->get('isglobal');
        $sort = $this->request->get('sort');
        $type = $this->request->get('type');
        $cityId = $this->request->get('cityid');
        $action = $this->request->get('action');
        $isLogin = $this->request->get('islogin');
        $startTime = $this->request->get('starttime');
        if(strstr($url, 'temp')) {
            $newUrl = 'upload/banner/' . $cityId . '_' . time();
            $newUrl = (UserMamagement::migrateBannerPhoto($url, $newUrl)) ? $newUrl : $url;
        } else {
            $newUrl = $url;
        }
        if($type == 'h5') {
            $content = $this->request->get('h5content');
        } elseif($type == 'shop') {
            $content = $this->request->get('shopid');
        } else {
            $content = '';
        }
        if($action == 'add') {
            $result = UserMamagement::addBanner($name, $newUrl, $isGlobal, $cityId, $type, $sort,$isLogin,$startTime,$content);
        } elseif($action == 'edit') {
            $result = UserMamagement::updateBanner($bannerId, $name, $newUrl, $isGlobal, $cityId, $type, $sort, $isLogin, $startTime, $content);
        } else {
            return $this->responseError('操作不对');
        }
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessMessage($result['message']);
        }
    }
    //获取Banner
    public function deleteBanner() {
        $bannerId = $this->request->get('bannerid');
        $result = UserMamagement::delBanner($bannerId);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessMessage($result['message']);
        }
    }
    //修改banner 的状态，下架，上架
    public function updateBannerStatus() {
        $bannerId = $this->request->get('bannerid');
        $status = $this->request->get('status');
        $result = UserMamagement::updateBannerStatus($bannerId,$status);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessMessage($result['message']);
        }
    }
    //app_start列表
    public function appStartList() {
        $cityId = $this->request->get('cityid');
        $appStartResult = UserMamagement::appStartList($cityId);
        if($appStartResult['status'] == 'failed') {
            $appStartLists = [];
        } else {
            $appStartLists = $appStartResult['data'];
        }
        $adminUser = Auth::guard('adminweb')->user();
        $roleId = $adminUser->roleid;
        if(($roleId != 1) && ($roleId != 2) && ($roleId != 5) && ($roleId != 7)) {
            $isGlobal = 0;
        } else {
            $isGlobal = 1;
        }
        $data = [
            'appstartlists'=>$appStartLists,
            'cityid' => $cityId,
            'isglobal' => $isGlobal,
        ];
        return view('console.user.app_start_list', $data);
    }
    //新增app_start   banner
    public function addAppStart() {
        $cityId = $this->request->get('cityid');
        $adminUser = Auth::guard('adminweb')->user();
        $adminUserId = $adminUser->id;
        $roleId = $adminUser->roleid;
        $ossData = Oss::getStsAuth();
        $AccessKeyId = isset($ossData['AccessKeyId']) ? $ossData['AccessKeyId']:'';
        $AccessKeySecret = isset($ossData['AccessKeySecret']) ? $ossData['AccessKeySecret']:'';
        $SecurityToken = isset($ossData['SecurityToken']) ? $ossData['SecurityToken']:'';
        $data = [
            'cityid' => $cityId,
            'adminUserId' => $adminUserId,
            'roleid' => $roleId,
            'action' => 'add',
            'type' => '',
            'AccessKeyId' => $AccessKeyId,
            'AccessKeySecret' => $AccessKeySecret,
            'SecurityToken' => $SecurityToken
        ];
        return view('console.user.new_app_start', $data);
    }
    //获取app_start 详情
    public function getAppStart() {
        $cityId = $this->request->get('cityid');
        $appStartId = $this->request->get('appstartid');
        $result = UserMamagement::getAppStart($appStartId);
        if($result['status'] == 'failed') {
            return view('errors.404');
        }
        $data = $result['data'];
        $adminUser = Auth::guard('adminweb')->user();
        $adminUserId = $adminUser->id;
        $roleId = $adminUser->roleid;
        $ossData = Oss::getStsAuth();
        $AccessKeyId = isset($ossData['AccessKeyId']) ? $ossData['AccessKeyId']:'';
        $AccessKeySecret = isset($ossData['AccessKeySecret']) ? $ossData['AccessKeySecret']:'';
        $SecurityToken = isset($ossData['SecurityToken']) ? $ossData['SecurityToken']:'';

        $data['cityid'] = $cityId;
        $data['adminUserId'] = $adminUserId;
        $data['roleid'] = $roleId;
        $data['action'] = 'edit';
        $data['AccessKeyId'] = $AccessKeyId;
        $data['AccessKeySecret'] = $AccessKeySecret;
        $data['SecurityToken'] = $SecurityToken;
        if(isset($data['type']) && ($data['type'] == 'shop')) {
            $shopId = $data['content'];
            $shopNameResult = ShopManagement::getShopNameByShopId($shopId);
            if($shopNameResult['status'] == 'failed') {
                $shopName = '';
            } else {
                $shopName = $shopNameResult['data'];
            }
        } else {
            $shopId = "";
            $shopName = "";
        }
        $data['shopid'] = $shopId;
        $data['shopname'] = $shopName;
        return view('console.user.app_start_modify', $data);
    }
    //编辑app_start
    public function editAppStart() {
        $cityId = $this->request->get('cityid');
        $action = $this->request->get('action');
        if($action == 'add') {
            //新增
            $name = $this->request->get('name');
            $picUrl = $this->request->get('banner');
            //$isGlobal = $this->request->get('isglobal');
            $isGlobal = 1; //默认全国
            $type = $this->request->get('type');
            $startTime = $this->request->get('starttime');
            $lastTime = $this->request->get('lasttime');
            if($type == 'h5') {
                $content = $this->request->get('h5content');
            } elseif($type == 'shop') {
                $content = $this->request->get('shopid');
            } else {
                $content = '';
            }
            $newUrl = 'upload/banner/appstart/' . $cityId . '_' . time();
            $newUrl = (UserMamagement::migrateBannerPhoto($picUrl, $newUrl)) ? $newUrl : $picUrl;
            $result = UserMamagement::addAppStart($name,$newUrl,$isGlobal,$cityId,$type, $startTime, $lastTime, $content);
        } elseif($action == 'edit') {
            //修改
            $appStartId = $this->request->get('appstartid');
            $name = $this->request->get('name');
            $picUrl = $this->request->get('banner');
            //$isGlobal = $this->request->get('isglobal');
            $isGlobal = 1; //默认全国
            $type = $this->request->get('type');
            $startTime = $this->request->get('starttime');
            $lastTime = $this->request->get('lasttime');
            if(strstr($picUrl, 'temp')) {
                $newUrl = 'upload/banner/appstart/' . $cityId . '_' . time();
                $newUrl = (UserMamagement::migrateBannerPhoto($picUrl, $newUrl)) ? $newUrl : $picUrl;
            } else {
                $newUrl = $picUrl;
            }
            if($type == 'h5') {
                $content = $this->request->get('h5content');
            } elseif($type == 'shop') {
                $content = $this->request->get('shopid');
            } else {
                $content = '';
            }
            $result = UserMamagement::updateAppStart($appStartId,$name,$newUrl,$isGlobal,$cityId,$type, $startTime, $lastTime, $content);
        } else {
            return $this->responseError('参数错误');
        }
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessMessage($result['message']);
        }
    }
    //删除app_start
    public function deleteAppStart() {
        $cityId = $this->request->get('cityid');
        $appStartId = $this->request->get('appstartid');
        $result = UserMamagement::delAppStart($appStartId);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessMessage($result['message']);
        }
    }
    //热搜管理
    public function hotSearch() {
        $cityId = $this->request->get('cityid');
        $result = Common::getSearchString($cityId);
        if($result['status'] == 'failed') {
            return view('errors.404');
        }
        $searchWords = $result['data'];
        $lists = [];
        $count = 1;
        foreach($searchWords as $key => $val) {
            $search = str_replace("SearchString:".$cityId.":", "", $key);
            $list = [
                'name' => $search,
                'count' => $val
            ];
            if($count > 50)  {
                break;
            }
            array_push($lists, $list);
            $count++;
        }
        $hotWordsResult = Common::hotWordList($cityId);
        if($hotWordsResult['status'] == 'failed') {
            $hotWords = [];
        } else {
            $hotWords = $hotWordsResult['data'];
        }
        $data = [
            'hotwordlists' => $hotWords,
            'searchlists' => $lists,
            'cityid' => $cityId,
        ];
        return view('console.user.hot_search', $data);
    }
    //新增热词
    public function addHotWord() {
        $word = $this->request->get('word');
        $cityId = $this->request->get('cityid');
        $result = Common::addHotWord($word, $cityId);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessMessage($result['message']);
        }
    }
    //删除热词
    public function deleteHotWord() {
        $word = $this->request->get('word');
        $cityId = $this->request->get('cityid');
        $result = Common::deleteHotWord($word, $cityId);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessMessage($result['message']);
        }
    }
    //修改热词排序
    public function updateHotWordSort() {
        $name = $this->request->get('name');
        $sort = $this->request->get('sort');
        $cityId = $this->request->get('cityid');
        $type = $this->request->get('type');
        $result = Common::updateHotWordSort($name, $cityId,$sort, $type);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessMessage($result['message']);
        }
    }
    //导出热搜
    public function exportHotSearch() {
        if($this->request->has('cityid')) {
            $cityId = $this->request->get('cityid');
        } else {
            $cityId = 1;
        }
        $cellData = [];
        $result = Common::getSearchString($cityId);
        $searchWords = $result['data'];
        foreach($searchWords as $key => $val) {
            $search = str_replace("SearchString:", "", $key);
            $list = [
                'name' => $search,
                'count' => $val
            ];
            array_push($cellData, $list);
        }
        $title = '热词';
        Excel::create($title,function($excel) use ($cellData){
            $excel->sheet('热词', function($sheet) use ($cellData){
                $sheet->rows($cellData);
            });
        })->export('xls');
        return $this->responseSuccessMessage('导出成功');
    }
    //帮助中心
    public function helpCenter() {
        return view('console.user.help_center');
    }
    //如何使用翻贝网
    public function userGuide() {
        return view('console.user.user_guide');
    }
    //反馈管理
    public function feedbackManage() {
        $cityId = $this->request->get('cityid');
        $type = "user";
        $result = Common::feedback($type,$cityId);
        if($result['status'] == 'failed') {
            return view('errors.404');
        }
        $lists = $result['data'];
        $data = [
            'lists' => $lists,
            'cityid' => $cityId
        ];
        return view('console.user.feedback_manage', $data);
    }
    //导出用户的反馈列表
    public function feedbackManageExport(){
        $cityId = $this->request->get('cityid');
        $type = $this->request->get('type');
        $result = Common::feedbackManageExport($type,$cityId);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        $data = $result['data'];
        $cellData = [['反馈内容','反馈时间','状态']];
        foreach($data as $list) {
            array_push($cellData, [
                'content'=>$list['content'],
                'created_at'=>$list['created_at'],
                'status'=>$list['status'] == 1?'已处理':'未处理',
            ]);
        }
        $title = '用户反馈管理列表';
        Excel::create($title,function($excel) use ($cellData){
            $excel->sheet('用户反馈管理列表', function($sheet) use ($cellData){
                $sheet->rows($cellData);
            });
        })->export('xls');
        return $this->responseSuccessMessage('导出成功');
    }
    //反馈管理
    public function feedbackDetailed() {
        $cityId = $this->request->get('cityid');
        $feedbackId = $this->request->get('feedbackid');
        $result = Common::getFeedbackDetail($feedbackId);
        if($result['status'] == 'failed') {
            return view('errors.404');
        }
        $data = $result['data'];
        $data['cityid'] = $cityId;
        return view('console.user.feedback_detailed', $data);
    }
    //处理反馈
    public function editFeedback() {
        $cityId = $this->request->get('cityid');
        $feedbackId = $this->request->get('feedbackid');
        $status = $this->request->get('status');
        $note = $this->request->get('note');
        $result = Common::editFeedback($feedbackId, $status, $note);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessMessage($result['message']);
        }
    }
    //消息管理
    public function messageManage() {
        return view('console.user.message_manage');
    }
    //消息管理
    public function messageCheck() {
        return view('console.user.message_check');
    }
}